package com.atguigu.auth.utils;

import com.atguigu.model.system.SysMenu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MenuHelper {

    public static List<SysMenu> buildTree(List<SysMenu> menuList) {
        return getAllChildren(0L,menuList);
    }

    public static List<SysMenu> getAllChildren(Long parentId,List<SysMenu> list){
        List<SysMenu> children = new ArrayList<>();
        for(SysMenu menu : list){
            if(menu.getParentId().equals(parentId)){
                children.add(menu);
                menu.setChildren(getAllChildren(menu.getId(),list));
            }
        }
        return children;
    }
}
